package com.metaapp.demo.net

import com.metaapp.demo.bean.SearchDataBean
import io.reactivex.Observable
import io.reactivex.ObservableTransformer
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.schedulers.Schedulers


/**
 * Created by chenlei on 2019/3/15.
 * Description :
 */
class RemoteRepository private constructor() {

    companion object {
        val instance = SingleInstance.holder
    }

    private object SingleInstance {
        val holder = RemoteRepository()
    }

    fun <T> switchThread(): ObservableTransformer<T, T> {
        return ObservableTransformer {
            it.subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
        }
    }

    fun getSearchPic(maps: MutableMap<String, Any>): Observable<SearchDataBean> {
        return HttpClient.getInstance()
            .getApiService()
            .getSearchPic(maps)
            .compose(switchThread())
    }
}

